home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / ams__l~1.zoo / src / sound.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-05  |  2.2 KB  |  105 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is part of the Atari Machine Specific Library,
  4. //  and is Copyright 1992 by Warwick W. Allison.
  5. //
  6. //  You are free to copy and modify these sources, provided you acknowledge
  7. //  the origin by retaining this notice, and adhere to the conditions
  8. //  described in the file COPYING.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11.  
  12. #include "Sound.h"
  13. #include <osbind.h>
  14.  
  15.  
  16. const int ToneRegister=0;
  17. const int VolumeRegister=8;
  18. const int SustainRegisterLow=11;
  19. const int SustainRegisterHigh=12;
  20. const int WaveformRegister=13;
  21. const int ControlRegister=7;
  22. const int NoisePeriodRegister=6;
  23.  
  24. #define GiWrite(v, r) Giaccess((v),128+(r))
  25. #define GiRead(r) Giaccess(0,(r))
  26.  
  27. void Sound(short Channel, short Pitch, short Volume)
  28. {
  29.     short VolumeReg=Channel+VolumeRegister;
  30.     short ToneReg=Channel+Channel+ToneRegister;
  31.  
  32.     GiWrite(Volume,VolumeReg);
  33.     GiWrite(Pitch&255,ToneReg);
  34.     GiWrite(Pitch>>8,ToneReg+1);
  35.     //GiWrite(GiRead(ControlRegister)&~(1<<Channel),ControlRegister);
  36. }
  37.  
  38.  
  39. void SoundControl(short Active, short Noisy)
  40. {
  41.     GiWrite(GiRead(ControlRegister)&192 | ((~Active)&7) | (((~Noisy)&7)<<3),ControlRegister);
  42. }
  43.  
  44.  
  45. void SetEnvelope(short WaveForm, short Period)
  46. {
  47.     GiWrite(Period&255,SustainRegisterLow);
  48.     GiWrite(Period>>8,SustainRegisterHigh);
  49.     GiWrite(WaveForm,WaveformRegister);
  50. }
  51.  
  52.  
  53. void SetNoisePeriod(short P)
  54. {
  55.     GiWrite(P,NoisePeriodRegister);
  56. }
  57.  
  58.  
  59. void SoundOff()
  60. {
  61.     SetNoisePeriod(0);
  62.     Sound(0,0,0);
  63.     Sound(1,0,0);
  64.     Sound(2,0,0);
  65.     SoundControl(0,0);
  66. }
  67.  
  68.  
  69. void SetPitch(short Channel, short Pitch)
  70. {
  71.     short ToneReg=Channel*2+ToneRegister;
  72.     GiWrite(Pitch&255,ToneReg);
  73.     GiWrite(Pitch>>8,ToneReg+1);
  74. }
  75.  
  76.  
  77. void SetVolume(short Channel, short Volume)
  78. {
  79.     GiWrite(Volume,VolumeRegister+Channel);
  80. }
  81.  
  82.  
  83. void SetNoisy(short Channel, bool Noisy)
  84. {
  85.     short NoiseBit=8<<Channel;
  86.  
  87.     if (Noisy) {
  88.         GiWrite(GiRead(ControlRegister) & ~NoiseBit,ControlRegister);
  89.     } else {
  90.         GiWrite(GiRead(ControlRegister) | NoiseBit,ControlRegister);
  91.     }
  92. }
  93.  
  94.  
  95. void SetActive(short Channel, bool Active)
  96. {
  97.     short ActiveBit=1<<Channel;
  98.  
  99.     if (Active) {
  100.         GiWrite(GiRead(ControlRegister) & ~ActiveBit,ControlRegister);
  101.     } else {
  102.         GiWrite(GiRead(ControlRegister) | ActiveBit,ControlRegister);
  103.     }
  104. }
  105.